<script type="text/javascript">
$(function(){
	var pg = App.batch.instIndex.ui, pp = pg.params;
	
	var gd = pg.find('.grid').mac('grid', {
		key: 'addr',
		cols: [{
			field: 'addr', title : '批量调度实例', width: 168
		},{
			field: 'catalog', title : '所属系统', width: 168
		},{
			field: 'lockTime', title : '最近锁定时间', width: 168
		},{
			field: 'lastTime', title : '最近签到时间', width: 168
		},{
			field: 'status', title : '状态', width: 78,
			render: function(r) {
				return Cache.batch.inst.status[r.status];
			}
		},{
			field: 'id', title : '操作', width: 120,
			render: function(r, tr, gd) {
				var p = $('<div></div>'), v = r.status,
					st = '<span class="a"></span>';
				if (r.status == 0) {
					$(st).click(function(){
						mac.confirm('确定要 删除 批量调度实例 ' + r.addr + ' 吗？', function(){
							$.post(App.ctx + '/inst/delete.do', {
								addr: r.addr
							}, function(rs){
								var ro = mac.eval(rs);
								if (ro.success) {
									gd.load();
								} else {
									mac.alert(ro.data, ro.params);
								}
							});
						});
					}).append('删除').appendTo(p);
				} else {
					$(st).click(function(){
						App.show({
							ctx: 'soagov',
							action: 'appMonitor',
							params: r
						}, function(r, s){
							App.show({
								ctx : 'batch',
								action : 'batchInstIndex',
								params : {}
							}, $.noop, pg.parent());
						}, pg.parent());
					}).append('查看监控').appendTo(p);
					//
					if (r.status == 1) {
						p.append('&nbsp;');
						$(st).click(function(){
							mac.confirm('确定要 设置 批量实例 ' + r.addr + ' 为主调度吗？', function(){
								$.post(App.ctx + '/inst/master.do', {
									addr: r.addr, catalog: r.catalog
								}, function(rs){
									debugger;
									var ro = mac.eval(rs);
									if (!ro.success) {
										mac.alert(ro.data, ro.params);
									}
									gd.load();
								});
							});
						}).append('设为主调度').appendTo(p);
					}
				}
				return p;
			}
		}],
		loader: {
			url: App.ctx + '/inst/list.do',
			params: { pageNo: 1, pageSize: 1000 },
			autoLoad: true
		},
		pagerLength: 10
	});
	
	pg.seek('refresh').click(function(){
// 		var w = mac.wait('Loading');
		gd.load();
// 		w.close();
	});
	
	function adjust(){
		var p = pg.parent(), w = p.width(), h = p.height();
		pg.width(w - 64);
		gd.parent().height(h - 96);
		gd.adjust();
	}
	$(window).resize(adjust);
	adjust();
});
</script>
 <div class="navi">
	<div class="title">
		<span class="a" name="back">批量调度</span>&gt;&gt;
		<span name="title">全部调度</span>
	</div>
</div>
<div class="head">
<!-- 	<input type="text" name="key" class="fr" placeholder="查找" /> -->
	<button name="refresh">手动刷新</button>
</div>
<div class="body">
	<div class="grid"></div>
</div>